package com.xiaoh.dormitoryrepairreportbackend.utils;

import com.xiaoh.dormitoryrepairreportbackend.model.dto.user.UserResponse;
import com.xiaoh.dormitoryrepairreportbackend.model.entity.GeneralUser;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户转换工具类
 * 用于将用户实体转换为响应DTO，过滤敏感信息
 */
public class UserConverter {

    /**
     * 将用户实体转换为响应DTO
     * 自动过滤密码等敏感信息
     */
    public static UserResponse toUserResponse(GeneralUser user) {
        if (user == null) {
            return null;
        }
        
        UserResponse userResponse = new UserResponse();
        BeanUtils.copyProperties(user, userResponse);
        return userResponse;
    }

    /**
     * 批量转换用户实体为响应DTO
     */
    public static List<UserResponse> toUserResponseList(List<GeneralUser> users) {
        if (users == null) {
            return null;
        }
        
        return users.stream()
                .map(UserConverter::toUserResponse)
                .collect(Collectors.toList());
    }
}
